package com.mtw.bbs.common.core.util;

import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler;
import org.springframework.stereotype.Component;
import java.util.concurrent.ScheduledFuture;

/**
 * 异步任务工具类
 */
@Slf4j
@Component
@AllArgsConstructor
public class ExecutorUtilz {

    private final ThreadPoolTaskScheduler schedulerExecutor;

    /**
     * 延迟300毫秒执行
     * @param task  任务
     */
    public <T> ScheduledFuture<T> delayedTask(Runnable task){
        log.error("delayedTask");
        return (ScheduledFuture<T>) schedulerExecutor.scheduleWithFixedDelay(task, 300);
    }


    /**
     * 延迟执行
     * @param task  任务
     * @param time  毫秒
     */
    public <T> ScheduledFuture<T> delayedTask(Runnable task,long time){
        log.error("delayedTask");
        return (ScheduledFuture<T>) schedulerExecutor.scheduleWithFixedDelay(task, time);
    }
}
